package org.road0329.tools.proto_parse_tool.enums;


import org.springframework.util.StringUtils;

public enum WaterMeterCollectorRespTypeEnum {
    CONFIRM_RECEIVE("0201","设备确认收到"),
    WRITE_DEVICE_ID("0210","写设备ID"),
    WRITE_IP_PORT("0211","写IP地址端口号"),
    WRITE_METER_TYPE("0212","写设备抄表的表类型"),
    WRITE_WAITING_TIME("0213","写设备抄表等待时间"),
    WRITE_START_TIME("0214","写设备抄表启动时间"),
    WRITE_INTERVAL_TIME("0215","写设备抄表间隔时间"),
    WRITE_PROTOCOL_PRIORITY("0218","写设备抄表协议优先级/协议组"),
    READ_DEVICE_ID("02A0","读设备ID"),
    READ_IP_PORT("02A1","读IP地址端口号"),
    READ_PARAMS("02AF","读设备多个参数"),
    RESET_DEVICE("02AA","设备复位"),
    RESET_FACTORY_INIT("02AB","恢复出厂设置"),
    ADD_METER_ID("02B0","添加所选表ID"),
    READ_METER_ID("02B1","读设备下已添加表的表ID"),
    DEL_METER_ID("02B2","删除所选表ID"),
    CLEAR_METER_ID("02B3","清空表ID"),
    CLOSE_VALVE("02B6","关阀"),
    OPEN_VALVE("02B7","开阀"),
    HEARTBEAT("0233", "设备上报心跳包数据"),
    REPORT_METER_READING_DATA("0222", "设备上报自动抄表数据"),
    REPORT_METER_READING_JUYUAN_DATA("0223", "设备上报自动抄表数据(炬源小时冻结)"),
    FIRM_SUMMARY("02C0", "下发概要信息"),
    FIRM_DATA_PACKET("02C1", "下发升级数据");

    private final String value;
    private final String text;

    WaterMeterCollectorRespTypeEnum(String value, String text) {
        this.value = value;
        this.text = text;
    }

    public String getValue() {
        return value;
    }

    public String getText() {
        return text;
    }

    public static String getText(String value) {
        WaterMeterCollectorRespTypeEnum em = getEnmuByValue(value);
        return em == null ? null : em.getText();
    }

    /**
     * 通过传入的字符串匹配枚举，传入值
     *
     * @param value
     * @return
     */
    public static WaterMeterCollectorRespTypeEnum getEnmuByValue(String value) {
        for (WaterMeterCollectorRespTypeEnum ie : WaterMeterCollectorRespTypeEnum.values()) {
            if (value.equals(ie.getValue())) {
                return ie;
            }
        }
        return null;
    }

    /**
     * 通过传入的字符串匹配枚举,传入名字
     *
     * @param name
     * @return
     */
    public static WaterMeterCollectorRespTypeEnum getEnmuByName(String name) {
        if (StringUtils.isEmpty(name)) {
            return null;
        }
        for (WaterMeterCollectorRespTypeEnum ie : WaterMeterCollectorRespTypeEnum.values()) {
            if (name.equalsIgnoreCase(ie.name())) {
                return ie;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return text;
    }
}
